﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SharpSoft.WPF.Controls
{
    /// <summary>
    /// 矢量图标控件
    /// </summary>
    public class VectorIcon : Control
    {
        static VectorIcon()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(VectorIcon), new FrameworkPropertyMetadata(typeof(VectorIcon)));
        }


        /// <summary>
        /// 背景图形
        /// </summary>
        public Shape BackgroundShape
        {
            get { return (Shape)GetValue(BackgroundShapeProperty); }
            set { SetValue(BackgroundShapeProperty, value); }
        }

        public static readonly DependencyProperty BackgroundShapeProperty =
            DependencyProperty.Register("BackgroundShape", typeof(Shape), typeof(VectorIcon), new PropertyMetadata(null));


        /// <summary>
        /// 前景图形
        /// </summary>
        public Shape ForegroundShape
        {
            get { return (Shape)GetValue(ForegroundShapeProperty); }
            set { SetValue(ForegroundShapeProperty, value); }
        }

        public static readonly DependencyProperty ForegroundShapeProperty =
            DependencyProperty.Register("ForegroundShape", typeof(Shape), typeof(VectorIcon), new PropertyMetadata(null));


        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            if (e.Property == ForegroundShapeProperty)
            {
                if (this.ForegroundShape != null)
                {
                    Binding binding = new Binding("Foreground") { Mode = BindingMode.TwoWay };
                    this.ForegroundShape.SetBinding(Shape.FillProperty, binding);
                }
            }
            else if (e.Property == BackgroundShapeProperty)
            {
                if (this.BackgroundShape != null)
                {
                    Binding binding = new Binding("Background") { Mode = BindingMode.TwoWay };
                    this.BackgroundShape.SetBinding(Shape.FillProperty, binding);
                }
            }
        }
    }
}
